package org.atlantis.grosbeak.castor;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("unchecked")
public class MapToPerson implements Castor<Map, Person> {

	public Type getFrom() {
		return Map.class;
	}

	public Type getTo() {
		return Person.class;
	}

	public Person obverseCast(Map src, Class<?> toType)
			throws FailToCastException {
		int id = (Integer) src.get("id");
		String name = (String) src.get("name");
		return new Person(id, name);
	}

	public Map reverseCast(Person src, Class<?> toType)
			throws FailToCastException {
		int id = src.getId();
		String name = src.getName();
		Map map = new HashMap();
		map.put("id", id);
		map.put("name", name);
		return map;
	}
}
